package services

import (
	"context"
	"wxapi/internal/svc"
	"wxapi/models"
)

func SymptomsList(ctx context.Context, svc *svc.ServiceContext) ([]*models.Symptom, error) {
	list := make([]*models.Symptom, 0)

	svc.Mysql.Model(&models.Symptom{}).Where("state = 100").Order("`order`").Find(&list)

	return list, nil
}

func GetSkillBySymptom(ctx context.Context, svc *svc.ServiceContext, symptomId int64) ([]*models.Skill, error) {
	s2sList := make([]*models.SymptomSkills, 0)
	svc.Mysql.Where("symptom_id = ?", symptomId).Order("`order`").Find(&s2sList)

	skillIdList := make([]int64, 0)
	for _, v := range s2sList {
		skillIdList = append(skillIdList, v.SkillId)
	}

	skillList := make([]*models.Skill, 0)
	svc.Mysql.Where("state = 100 AND id in (?)", skillIdList).Order("`order`").Find(&skillList)

	return skillList, nil
}
